package com.nmsl.sn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.sn.domain.SnPhysicalInfo;
import com.nmsl.sn.service.ISnPhysicalInfoService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 体格信息Controller
 * 
 * @author sn
 * @date 2025-02-21
 */
@RestController
@RequestMapping("/sn/info")
public class SnPhysicalInfoController extends BaseController
{
    @Autowired
    private ISnPhysicalInfoService snPhysicalInfoService;

    /**
     * 查询体格信息列表
     */
    @PreAuthorize("@ss.hasPermi('sn:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnPhysicalInfo snPhysicalInfo)
    {
        startPage();
        List<SnPhysicalInfo> list = snPhysicalInfoService.selectSnPhysicalInfoList(snPhysicalInfo);
        return getDataTable(list);
    }

    /**
     * 导出体格信息列表
     */
    @PreAuthorize("@ss.hasPermi('sn:info:export')")
    @Log(title = "体格信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnPhysicalInfo snPhysicalInfo)
    {
        List<SnPhysicalInfo> list = snPhysicalInfoService.selectSnPhysicalInfoList(snPhysicalInfo);
        ExcelUtil<SnPhysicalInfo> util = new ExcelUtil<SnPhysicalInfo>(SnPhysicalInfo.class);
        util.exportExcel(response, list, "体格信息数据");
    }

    /**
     * 获取体格信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('sn:info:query')")
    @GetMapping(value = "/{physicalInfoId}")
    public AjaxResult getInfo(@PathVariable("physicalInfoId") Long physicalInfoId)
    {
        return success(snPhysicalInfoService.selectSnPhysicalInfoByPhysicalInfoId(physicalInfoId));
    }

    /**
     * 新增体格信息
     */
    @PreAuthorize("@ss.hasPermi('sn:info:add')")
    @Log(title = "体格信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SnPhysicalInfo snPhysicalInfo)
    {
        System.out.println("SnPhysicalInfo: " + snPhysicalInfo);
        return toAjax(snPhysicalInfoService.insertSnPhysicalInfo(snPhysicalInfo));
    }

    /**
     * 修改体格信息
     */
    @PreAuthorize("@ss.hasPermi('sn:info:edit')")
    @Log(title = "体格信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SnPhysicalInfo snPhysicalInfo)
    {
        return toAjax(snPhysicalInfoService.updateSnPhysicalInfo(snPhysicalInfo));
    }

    /**
     * 删除体格信息
     */
    @PreAuthorize("@ss.hasPermi('sn:info:remove')")
    @Log(title = "体格信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{physicalInfoIds}")
    public AjaxResult remove(@PathVariable Long[] physicalInfoIds)
    {
        return toAjax(snPhysicalInfoService.deleteSnPhysicalInfoByPhysicalInfoIds(physicalInfoIds));
    }
}
